package com.ewanghuiju.app.ui.my.adapter;

import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.ewanghuiju.app.R;
import com.ewanghuiju.app.model.bean.local.FansInfoBean;
import com.ewanghuiju.app.util.ClipboardUtils;
import com.ewanghuiju.app.util.StringUtil;
import com.makeramen.roundedimageview.RoundedImageView;
import com.stx.xhb.androidx.OnDoubleClickListener;

/**
 * @author sj  qq:751943509
 * @class 我的团队粉丝列表 adapter
 * @time 2020/2/20
 */
public class FansInfoListAdapter extends BaseQuickAdapter<FansInfoBean, BaseViewHolder> {

    public FansInfoListAdapter(int layoutResId) {
        super(layoutResId);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    protected void convert(BaseViewHolder helper, FansInfoBean item) {
        helper.setText(R.id.tv_nickname, StringUtil.getLengthTextByStr(item.getNickname(), 8));

        helper.setText(R.id.tv_vip_info, StringUtil.getDailiInfo(item.getIs_daili()));
        //直属粉丝
        helper.setText(R.id.tv_zs_fans, item.getDirectly_fans());
        //粉丝级别
        helper.setText(R.id.tv_fans_level, item.getPath_path());
        //时间
        helper.setText(R.id.tv_time, item.getCreate_time());
        //订单数量
        helper.setText(R.id.tv_order_num, item.getBuy_num());

        TextView tv_phone_copy = helper.getView(R.id.tv_phone_copy);
        TextView tv_wx_copy = helper.getView(R.id.tv_wx_copy);
        tv_phone_copy.setText(TextUtils.isEmpty(item.getMobile()) ? "未设置" : item.getMobile());
        tv_wx_copy.setText(TextUtils.isEmpty(item.getWx_card()) ? "未设置" : item.getWx_card());
        tv_phone_copy.setOnClickListener(new OnDoubleClickListener() {
            @Override
            public void onNoDoubleClick(View v) {
                if (item != null && !TextUtils.isEmpty(item.getMobile())) {
                    ClipboardUtils.copyText(item.getMobile(), "复制成功");
                }
            }
        });

        tv_wx_copy.setOnClickListener(new OnDoubleClickListener() {
            @Override
            public void onNoDoubleClick(View v) {
                if (item != null && !TextUtils.isEmpty(item.getWx_card())) {
                    ClipboardUtils.copyText(item.getWx_card(), "复制成功");
                }
            }
        });

        RoundedImageView riv = helper.getView(R.id.riv_head);
        Glide.with(mContext).load(item.getAvatar()).placeholder(R.mipmap.icon_default_head).error(R.mipmap.icon_default_head).into(riv);
    }
}
